/**
 * Copyright (c) 2012 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.android.wordbattle;

import java.util.Locale;

import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * This activity will present a screen in which the user can select in which modi he wants to play
 * 
 *  - single player
 *  - multi player local
 *  - multi player internet
 */

public class WordBattleSelectionActivity extends AbstractWordBattleActivity {

  public WordBattleSelectionActivity(){
    init();
  }

  private void init(){
    WordRasterContext.init( this );
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
//    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
//      return true;
//    }
    return super.onKeyDown(keyCode, event);
  }


  @Override
  public void onCreate(Bundle savedInstanceState) {
    /*
      super.onCreate(savedInstanceState);
      // Create a new ImageView
      ImageView imageView = new ImageView(this);
      // Set the background color to white
      imageView.setBackgroundColor(Color.WHITE);
      // Parse the SVG file from the resource
      SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.topbar);
      // Get a drawable from the parsed SVG and set it as the drawable for the ImageView
      imageView.setImageDrawable(svg.createPictureDrawable());
      // Set the ImageView as the content view for the Activity
      setContentView(imageView);

     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basic_game_mode_selection);

    ButtonListener theButtonListener = new ButtonListener();
    ((Button)findViewById( R.id.BTNBoggleBasic )).setOnClickListener( theButtonListener );
    ((Button)findViewById( R.id.BTNBoggleWood )).setOnClickListener( theButtonListener );
    ((Button)findViewById( R.id.BTNWordSearch )).setOnClickListener( theButtonListener );
    ((Button)findViewById( R.id.BTNBoggleSnake )).setOnClickListener( theButtonListener );
    ((Button)findViewById( R.id.BTNSVGTest)).setOnClickListener( theButtonListener );
    ((Button)findViewById( R.id.BTNBoggleMerge)).setOnClickListener( theButtonListener );
    ((Button)findViewById( R.id.BtnBoggleCrossTile)).setOnClickListener( theButtonListener );

  }

  public class ButtonListener implements OnClickListener {

    @Override
    public void onClick( View aView ) {
      String theLanguage = PreferenceManager.getDefaultSharedPreferences(WordBattleSelectionActivity.this).getString("languagePref", Locale.getDefault().getLanguage() );
      WordRasterContext.getInstance().getDatabaseLoaderDecorator().loadLanguage(theLanguage);

      
      Intent theWordBattleActivity = new Intent(WordBattleSelectionActivity.this, WordBattleActivity.class);
      theWordBattleActivity.putExtra( "language", theLanguage );
      
      if(aView == findViewById( R.id.BTNBoggleBasic )){
        theWordBattleActivity.putExtra( "rows", 5 );
        theWordBattleActivity.putExtra( "columns", 4 );
        theWordBattleActivity.putExtra( "gameStyle", WordRasterGameMediatorFactory.GameType.SIMPLE_BOGGLE_STYLE.toString() );
      } else if(aView == findViewById( R.id.BTNBoggleWood )){
        theWordBattleActivity.putExtra( "rows", 5 );
        theWordBattleActivity.putExtra( "columns", 4 );
        theWordBattleActivity.putExtra( "gameStyle", WordRasterGameMediatorFactory.GameType.BOGGLE_STYLE.toString() );
      } else if(aView == findViewById( R.id.BTNWordSearch )){
        theWordBattleActivity.putExtra( "rows", 10 );
        theWordBattleActivity.putExtra( "columns", 8 );
        theWordBattleActivity.putExtra( "gameStyle", WordRasterGameMediatorFactory.GameType.CLASSIC_STYLE.toString() );
      } else if(aView == findViewById( R.id.BTNBoggleSnake )){
        theWordBattleActivity.putExtra( "rows", 5 );
        theWordBattleActivity.putExtra( "columns", 5 );
        theWordBattleActivity.putExtra( "gameStyle", WordRasterGameMediatorFactory.GameType.SNAKE_SIMPLE_BOGGLE_STYLE.toString() );
      } else if(aView == findViewById( R.id.BTNBoggleMerge )){
        theWordBattleActivity.putExtra( "rows", 5 );
        theWordBattleActivity.putExtra( "columns", 5 );
        theWordBattleActivity.putExtra( "gameStyle", WordRasterGameMediatorFactory.GameType.BOGGLE_MERGE.toString() );
      } else if(aView == findViewById( R.id.BTNSVGTest )){
        Intent theSvgTestIntent = new Intent(WordBattleSelectionActivity.this, SVGTestActivity.class);
        theSvgTestIntent.putExtra("svg", R.raw.gui);
        startActivity(theSvgTestIntent);
        return;
      } else if(aView == findViewById( R.id.BtnBoggleCrossTile )){
    	theWordBattleActivity.putExtra( "rows", 5 );
        theWordBattleActivity.putExtra( "columns", 5 );
        theWordBattleActivity.putExtra( "gameStyle", WordRasterGameMediatorFactory.GameType.BOGGLE_CROSSTILE.toString() );
      }

      startActivity(theWordBattleActivity);
    }

  }
}
